pwd
# this is a comment and will not be run
print('hello everyone')
'''
this
is a
multi line comment
'''
"""
so
is this
"""
print('hello again')
type(3)
type(3.4)
type(False)
type("3")
x = True
y = 3
z = "cat"
aa = "45"
print(x, y, z, aa)
3 + 3
3/2.0
# exponents
2 ** 3
# modulo
10 % 3
3 > 1
# string concatenation
"cat" + " and dog"
# using only the number 4 and 6
# 8
6 + 6 - 4
# this is but a flesh wound
'this is but' + ' a flesh wound'
# lists
my_list = []
type(my_list)
[1, 3, 4, 5, 6, 10]
[1, 3, "3", True]
my_list = [1, 3, 5, True]
print(my_list)
atgc = ['adenine', 'guaniene', 'thyeme', 'cytoscene?']
atgc[0]
atgc[-3]
# slicing
atgc[1:3]
atgc[:3]
atgc.append('uracil')
atgc
id(atgc[4])
id(atgc[5])
atgc.pop()
del atgc[2]
atgc
type(atgc)
atgc[3] = 'tyieme'
atgc
my_tuple = ()
type(my_tuple)
my_tuple = (3, 4, 5)
my_tuple[1] = 99
x = [5, 6, 7]
y = x
print(x, y)
x[0] = 23
print(x)
print(y)
id(x)
id(y)
help(list)
my_list.sort()
print(my_list)
names = ["daniel", "gabe", "camille"]
print(names.sort())
names
my_string = "thisisastring"
print(my_string)
#capitalize first word
print(my_string.capitalize())
# did this change my variable?
print(my_string)
my_string = my_string.capitalize()
print(my_string)
# is 'daniel' in my list of names?
type("daniel" in names)
len("daniel")
# dictionaries
my_dic = {}
type(my_dic)
# creating a dictionary key:value
my_dic = {"daniel":"chen", "camille":"ostrichnSpanish"}
print(my_dic)
# getting value out of dictionary
my_dic["daniel"]
# re-assigning a value of a key in a dictionary
my_dic["daniel"] = "wild goose"
my_dic
# adding new key:value pair to list
my_dic["gabe"] = "periz-something"
my_dic
# deleting element from list
del my_dic['daniel']
my_dic
my_dic['daniel'] = 25
my_dic
# return value
my_dic['daniel']
my_dic['asdf']
my_dic.get('daniel')
type(my_dic.get('asdf'))
'daniel' in my_dic
'asdf' in my_dic
- how would you assign these values to a python dictionary?
fname | daniel
lname | chen
age | 25
height | 69
weight | 180
- how would you store the above data in a single dictionary entry?
(You could accomplish this using a list of the above values, but a more straightforward solution is like a database: simply store the dictionary above with an appropriate key, such as a number or name.)
# oops
my_dic = {fname:"daniel", lname:"chen", age:25, height:69, weight:180}
my_dic = {"fname":"daniel", "lname":"chen", "age":25, "height":69, "weight":180}
my_dic
fname = 'daniel_again'
lname = 'wild goose'
age = 99
height = 34
weight = 444
my_dic = {"fname":fname, "lname":lname, "age":age, "height":height, "weight":weight}
my_dic
my_other_dic = {1: my_dic}
my_other_dic
my_other_dic[1]
my_other_dic.get(1)
#getting value from a dict
# where this dic is a value of a parent dict
my_other_dic.get(1).get('fname')
# merging dicts
my_new_dict = {}
my_new_dict.update(my_other_dic)
my_new_dict
# flow control
# if/else
if (something boolean): something to do if true someting else to do if ture and yet another
this will be run regarless
if "asdf" == "daniel":
print('hello i can spell!')
print(x_1)
x_1 = x_1 **2
print(x_1)
print('boo')
names = ["daniel", "chicken"]
if "asdf" in names:
print('daniel is in names')
elif 'chicken' in names:
print('found a chicken')
else:
print("i found nothing")
print('finished')
10 % 3
# given a dict of fname, lname, and age
my_dict = {'fname':'daniel', 'lname':'chn', 'age':25}
# if your fname has the letter 'e', print your first name
# if your lname does not have the letter 'e', print your last name
# otherwise, print your age
# if your fname has the letter 'e', print your first name
if 'e' in my_dict['fname']:
print(my_dict.get('fname'))
# if your lname does not have the letter 'e', print your last name
elif (not ('e' in my_dict.get('lname'))):
print(my_dict['lname'])
# otherwise, print your age
else:
print(my_dict['age'])
'daniel' == 'daniel'
not 'daniel' == 'daniel'
my_list = [1, 2, 3, 4, 5]
4 in my_list
'd' in 'daniel'
my_dict